Check for vias inside pads - #180
Merged
Merged
Conversation
Comment on lines
+49
to
+157
| test("reports a via whose center is inside an SMD pad", async () => { | ||
| const circuitJson: AnyCircuitElement[] = [makeBoard(), rectPad, viaInRectPad] | ||
|
|
||
| const errors = checkViasInPads(circuitJson) | ||
|
|
||
| expect(errors).toHaveLength(1) | ||
| expect(errors[0]).toMatchObject({ | ||
| type: "pcb_placement_error", | ||
| pcb_placement_error_id: "via_in_pad_pcb_via_1_pcb_smtpad_1", | ||
| error_type: "pcb_placement_error", | ||
| }) | ||
| expect(errors[0].message).toContain("is inside SMD pad") | ||
| expect(containsCircuitJsonId(errors[0].message)).toBe(false) | ||
| expect(await runAllPlacementChecks(circuitJson)).toContainEqual(errors[0]) | ||
| }) | ||
|
|
||
| test("uses true pad geometry for circular, polygon, and plated-hole pads", () => { | ||
| const circuitJson: AnyCircuitElement[] = [ | ||
| makeBoard(), | ||
| { | ||
| type: "pcb_smtpad", | ||
| pcb_smtpad_id: "pcb_smtpad_circle", | ||
| shape: "circle", | ||
| x: -4, | ||
| y: 0, | ||
| radius: 0.5, | ||
| layer: "top", | ||
| }, | ||
| { | ||
| type: "pcb_smtpad", | ||
| pcb_smtpad_id: "pcb_smtpad_polygon", | ||
| shape: "polygon", | ||
| points: [ | ||
| { x: -0.5, y: -0.5 }, | ||
| { x: 0.5, y: -0.5 }, | ||
| { x: 0, y: 0.5 }, | ||
| ], | ||
| layer: "top", | ||
| }, | ||
| { | ||
| type: "pcb_plated_hole", | ||
| pcb_plated_hole_id: "pcb_plated_hole_1", | ||
| shape: "circle", | ||
| x: 4, | ||
| y: 0, | ||
| outer_diameter: 1, | ||
| hole_diameter: 0.5, | ||
| layers: ["top", "bottom"], | ||
| }, | ||
| { | ||
| ...viaInRectPad, | ||
| pcb_via_id: "pcb_via_circle", | ||
| x: -4.2, | ||
| y: 0, | ||
| }, | ||
| { | ||
| ...viaInRectPad, | ||
| pcb_via_id: "pcb_via_polygon", | ||
| x: 0, | ||
| y: 0, | ||
| }, | ||
| { | ||
| ...viaInRectPad, | ||
| pcb_via_id: "pcb_via_plated_hole", | ||
| x: 4, | ||
| y: 0, | ||
| }, | ||
| ] | ||
|
|
||
| expect(checkViasInPads(circuitJson)).toHaveLength(3) | ||
| }) | ||
|
|
||
| test("ignores vias outside pads and vias on non-overlapping layers", () => { | ||
| const circuitJson: AnyCircuitElement[] = [ | ||
| makeBoard(), | ||
| rectPad, | ||
| { | ||
| ...viaInRectPad, | ||
| pcb_via_id: "pcb_via_outside", | ||
| x: 2, | ||
| y: 2, | ||
| }, | ||
| { | ||
| ...viaInRectPad, | ||
| pcb_via_id: "pcb_via_inner_layers", | ||
| x: 0, | ||
| y: 0, | ||
| layers: ["inner1", "inner2"], | ||
| }, | ||
| ] | ||
|
|
||
| expect(checkViasInPads(circuitJson)).toEqual([]) | ||
| }) | ||
|
|
||
| test("respects the board via-in-pad allowance", () => { | ||
| const allowedCircuit: AnyCircuitElement[] = [ | ||
| makeBoard(true), | ||
| rectPad, | ||
| viaInRectPad, | ||
| ] | ||
| const disallowedCircuit: AnyCircuitElement[] = [ | ||
| makeBoard(false), | ||
| rectPad, | ||
| viaInRectPad, | ||
| ] | ||
|
|
||
| expect(checkViasInPads(allowedCircuit)).toEqual([]) | ||
| expect(checkViasInPads(disallowedCircuit)).toHaveLength(1) | ||
| }) |
Contributor
There was a problem hiding this comment.
This file contains 4 test(...) calls (at lines 49, 65, 121, and 143), but the style guide requires that a *.test.ts file may have AT MOST one test(...). After the first test, the remaining tests should be split into separate, numbered files. For example: check-vias-in-pads1.test.ts, check-vias-in-pads2.test.ts, check-vias-in-pads3.test.ts, and check-vias-in-pads4.test.ts.
Suggested change
| test("reports a via whose center is inside an SMD pad", async () => { | |
| const circuitJson: AnyCircuitElement[] = [makeBoard(), rectPad, viaInRectPad] | |
| const errors = checkViasInPads(circuitJson) | |
| expect(errors).toHaveLength(1) | |
| expect(errors[0]).toMatchObject({ | |
| type: "pcb_placement_error", | |
| pcb_placement_error_id: "via_in_pad_pcb_via_1_pcb_smtpad_1", | |
| error_type: "pcb_placement_error", | |
| }) | |
| expect(errors[0].message).toContain("is inside SMD pad") | |
| expect(containsCircuitJsonId(errors[0].message)).toBe(false) | |
| expect(await runAllPlacementChecks(circuitJson)).toContainEqual(errors[0]) | |
| }) | |
| test("uses true pad geometry for circular, polygon, and plated-hole pads", () => { | |
| const circuitJson: AnyCircuitElement[] = [ | |
| makeBoard(), | |
| { | |
| type: "pcb_smtpad", | |
| pcb_smtpad_id: "pcb_smtpad_circle", | |
| shape: "circle", | |
| x: -4, | |
| y: 0, | |
| radius: 0.5, | |
| layer: "top", | |
| }, | |
| { | |
| type: "pcb_smtpad", | |
| pcb_smtpad_id: "pcb_smtpad_polygon", | |
| shape: "polygon", | |
| points: [ | |
| { x: -0.5, y: -0.5 }, | |
| { x: 0.5, y: -0.5 }, | |
| { x: 0, y: 0.5 }, | |
| ], | |
| layer: "top", | |
| }, | |
| { | |
| type: "pcb_plated_hole", | |
| pcb_plated_hole_id: "pcb_plated_hole_1", | |
| shape: "circle", | |
| x: 4, | |
| y: 0, | |
| outer_diameter: 1, | |
| hole_diameter: 0.5, | |
| layers: ["top", "bottom"], | |
| }, | |
| { | |
| ...viaInRectPad, | |
| pcb_via_id: "pcb_via_circle", | |
| x: -4.2, | |
| y: 0, | |
| }, | |
| { | |
| ...viaInRectPad, | |
| pcb_via_id: "pcb_via_polygon", | |
| x: 0, | |
| y: 0, | |
| }, | |
| { | |
| ...viaInRectPad, | |
| pcb_via_id: "pcb_via_plated_hole", | |
| x: 4, | |
| y: 0, | |
| }, | |
| ] | |
| expect(checkViasInPads(circuitJson)).toHaveLength(3) | |
| }) | |
| test("ignores vias outside pads and vias on non-overlapping layers", () => { | |
| const circuitJson: AnyCircuitElement[] = [ | |
| makeBoard(), | |
| rectPad, | |
| { | |
| ...viaInRectPad, | |
| pcb_via_id: "pcb_via_outside", | |
| x: 2, | |
| y: 2, | |
| }, | |
| { | |
| ...viaInRectPad, | |
| pcb_via_id: "pcb_via_inner_layers", | |
| x: 0, | |
| y: 0, | |
| layers: ["inner1", "inner2"], | |
| }, | |
| ] | |
| expect(checkViasInPads(circuitJson)).toEqual([]) | |
| }) | |
| test("respects the board via-in-pad allowance", () => { | |
| const allowedCircuit: AnyCircuitElement[] = [ | |
| makeBoard(true), | |
| rectPad, | |
| viaInRectPad, | |
| ] | |
| const disallowedCircuit: AnyCircuitElement[] = [ | |
| makeBoard(false), | |
| rectPad, | |
| viaInRectPad, | |
| ] | |
| expect(checkViasInPads(allowedCircuit)).toEqual([]) | |
| expect(checkViasInPads(disallowedCircuit)).toHaveLength(1) | |
| }) | |
| test("reports a via whose center is inside an SMD pad", async () => { | |
| const circuitJson: AnyCircuitElement[] = [makeBoard(), rectPad, viaInRectPad] | |
| const errors = checkViasInPads(circuitJson) | |
| expect(errors).toHaveLength(1) | |
| expect(errors[0]).toMatchObject({ | |
| type: "pcb_placement_error", | |
| pcb_placement_error_id: "via_in_pad_pcb_via_1_pcb_smtpad_1", | |
| error_type: "pcb_placement_error", | |
| }) | |
| expect(errors[0].message).toContain("is inside SMD pad") | |
| expect(containsCircuitJsonId(errors[0].message)).toBe(false) | |
| expect(await runAllPlacementChecks(circuitJson)).toContainEqual(errors[0]) | |
| }) | |
Spotted by Graphite (based on custom rule: Custom rule)
Is this helpful? React 👍 or 👎 to let us know.
Contributor
|
Thank you for your contribution! 🎉 PR Rating: ⭐⭐ Track your contributions and see the leaderboard at: tscircuit Contribution Tracker |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
checkViasInPadsrunAllPlacementChecks/runAllCheckspcb_board.is_via_in_pad_allowedis explicitlytrueWhy
Via-in-pad usually requires an intentional manufacturing process. With the new circuit-json board flag, checks can reject accidental vias in pads while allowing designs that explicitly opt in.
The rule uses backward-compatible feature detection for the board flag so this focused PR does not need to pull in unrelated schema migrations through the repository's pinned development dependency.
Validation
bun test tests/lib/check-vias-in-pads.test.ts(4 passing)bun test(141 passing)bunx tsc --noEmitbun run buildbunx @tscircuit/dependency-checkgit diff --check